package com.qf.mq;
import com.rabbitmq.client.AMQP;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * author:z
 * time:2022/1/3 20:51
 * description:
 */
@Slf4j
@Component
public class MqListener {

    @Autowired
    RabbitTemplate rabbitTemplate;

    //获取mq中未消费的条数
    public int getMqMessagesCount(String queue){
        //获取未消费的mq的信息
        AMQP.Queue.DeclareOk execute = rabbitTemplate.execute(channel -> channel.queueDeclarePassive(queue));
        return execute.getMessageCount();
    }
}
